/*   1:    */ package com.atomikos.beans;
/*   2:    */ 
/*   3:    */ import java.awt.BorderLayout;
/*   4:    */ import java.awt.Dimension;
/*   5:    */ import java.awt.Font;
/*   6:    */ import java.awt.GridLayout;
/*   7:    */ import java.awt.event.ActionEvent;
/*   8:    */ import java.awt.event.ActionListener;
/*   9:    */ import java.beans.PropertyChangeEvent;
/*  10:    */ import java.beans.PropertyChangeListener;
/*  11:    */ import java.io.PrintStream;
/*  12:    */ import java.util.ArrayList;
/*  13:    */ import javax.swing.JButton;
/*  14:    */ import javax.swing.JLabel;
/*  15:    */ import javax.swing.JOptionPane;
/*  16:    */ import javax.swing.JPanel;
/*  17:    */ import javax.swing.JScrollPane;
/*  18:    */ 
/*  19:    */ public class BeanWizard
/*  20:    */   implements PropertyChangeListener
/*  21:    */ {
/*  22:    */   private JPanel panel_;
/*  23:    */   private BeanInspector inspector_;
/*  24:    */   
/*  25:    */   private static Property[] filterProperties(Property[] props)
/*  26:    */     throws PropertyException
/*  27:    */   {
/*  28: 68 */     if (props == null) {
/*  29: 68 */       return null;
/*  30:    */     }
/*  31: 70 */     ArrayList list = new ArrayList();
/*  32: 72 */     for (int i = 0; i < props.length; i++) {
/*  33: 73 */       if ((!props[i].isHidden()) && (!props[i].isReadOnly()) && (props[i].getEditor() != null)) {
/*  34: 76 */         list.add(props[i]);
/*  35:    */       }
/*  36:    */     }
/*  37: 84 */     return (Property[])list.toArray(new Property[0]);
/*  38:    */   }
/*  39:    */   
/*  40:    */   public BeanWizard(Object bean)
/*  41:    */     throws PropertyException
/*  42:    */   {
/*  43: 95 */     this.panel_ = new JPanel();
/*  44: 96 */     this.panel_.setLayout(new BorderLayout());
/*  45: 97 */     JPanel tempPanel = new JPanel();
/*  46: 98 */     this.inspector_ = new BeanInspector(bean);
/*  47: 99 */     Property[] properties = filterProperties(this.inspector_.getProperties());
/*  48:100 */     int rows = 0;
/*  49:101 */     if (properties != null) {
/*  50:101 */       rows = properties.length;
/*  51:    */     }
/*  52:102 */     tempPanel.setLayout(new GridLayout(rows, 1));
/*  53:103 */     for (int i = 0; i < rows; i++)
/*  54:    */     {
/*  55:104 */       JPanel propertyPanel = new JPanel();
/*  56:    */       
/*  57:106 */       propertyPanel.setLayout(new GridLayout(1, 2));
/*  58:107 */       JLabel nameLabel = new JLabel(properties[i].getName());
/*  59:109 */       if (properties[i].isPreferred())
/*  60:    */       {
/*  61:110 */         Font font = new Font("SansSerif", 1, 12);
/*  62:111 */         nameLabel.setFont(font);
/*  63:    */       }
/*  64:    */       else
/*  65:    */       {
/*  66:114 */         Font font = new Font("SansSerif", 0, 12);
/*  67:115 */         nameLabel.setFont(font);
/*  68:    */       }
/*  69:117 */       propertyPanel.add(nameLabel);
/*  70:119 */       if (properties[i].getIndexedProperty() != null)
/*  71:    */       {
/*  72:120 */         JButton button = new JButton("Edit");
/*  73:121 */         button.addActionListener(new ButtonListener(properties[i]));
/*  74:122 */         propertyPanel.add(button);
/*  75:    */       }
/*  76:    */       else
/*  77:    */       {
/*  78:125 */         propertyPanel.add(properties[i].getEditor().getComponent());
/*  79:    */       }
/*  80:126 */       properties[i].getEditor().addPropertyChangeListener(this);
/*  81:    */       
/*  82:128 */       tempPanel.add(propertyPanel);
/*  83:129 */       this.panel_.setPreferredSize(new Dimension(300, 300));
/*  84:130 */       this.panel_.add(new JScrollPane(tempPanel), "Center");
/*  85:    */     }
/*  86:    */   }
/*  87:    */   
/*  88:    */   public JPanel getPanel()
/*  89:    */   {
/*  90:146 */     return this.panel_;
/*  91:    */   }
/*  92:    */   
/*  93:    */   public Object getBean()
/*  94:    */   {
/*  95:159 */     if (this.inspector_ == null) {
/*  96:159 */       return null;
/*  97:    */     }
/*  98:160 */     return this.inspector_.getBean();
/*  99:    */   }
/* 100:    */   
/* 101:    */   public void propertyChange(PropertyChangeEvent event)
/* 102:    */   {
/* 103:165 */     Editor editor = (Editor)event.getSource();
/* 104:166 */     Property property = editor.getProperty();
/* 105:167 */     System.err.println("BeanWizard: propertyChange");
/* 106:    */     try
/* 107:    */     {
/* 108:169 */       System.err.println(editor.getEditedObject().getClass().getName());
/* 109:170 */       property.setValue(editor.getEditedObject());
/* 110:171 */       System.err.println("Property set: " + property.getName());
/* 111:172 */       System.err.println("to value: " + editor.getEditedObject());
/* 112:    */     }
/* 113:    */     catch (Exception e)
/* 114:    */     {
/* 115:175 */       e.printStackTrace();
/* 116:    */     }
/* 117:    */   }
/* 118:    */   
/* 119:    */   static class ButtonListener
/* 120:    */     implements ActionListener
/* 121:    */   {
/* 122:    */     private Property property_;
/* 123:    */     
/* 124:    */     ButtonListener(Property property)
/* 125:    */     {
/* 126:186 */       this.property_ = property;
/* 127:    */     }
/* 128:    */     
/* 129:    */     public void actionPerformed(ActionEvent e)
/* 130:    */     {
/* 131:    */       try
/* 132:    */       {
/* 133:192 */         JOptionPane.showMessageDialog(null, this.property_.getEditor().getComponent(), "Edit", -1);
/* 134:    */       }
/* 135:    */       catch (Exception ex)
/* 136:    */       {
/* 137:196 */         ex.printStackTrace();
/* 138:    */       }
/* 139:    */     }
/* 140:    */   }
/* 141:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\atomikos-util\3.7.0\atomikos-util-3.7.0.jar
 * Qualified Name:     com.atomikos.beans.BeanWizard
 * JD-Core Version:    0.7.0.1
 */